<template>
	<view class="build">
		<Navbar>我的建筑</Navbar>
		<view class="tabs">
			<view class="item" :class="active==1?'active':''" @click="changeActive(1)">我的建筑</view>
			<view class="item" :class="active==2?'active':''" @click="changeActive(2)">出售中</view>
			<view class="item" :class="active==3?'active':''" @click="changeActive(3)">已出售</view>
		</view>
		<scroll-view scroll-y class="scroll_view">
			<view class="list">
				<view class="item" v-for="item in list">
					<view class="cover">
						<image :src="item.product_cover"></image>
					</view>
					<view class="item_view">
						<view class="grade">
							<text class="key">{{item.product_name}}</text>
							<!-- <text class="value">Lv1</text> -->
						</view>
						<view class="progress_box">
							<view class="key">耐久度：</view>
							<view class="progress_view">
								<view class="progress" :style="{width:item.durability>100?100:item.durability+'%'}">
								</view>
								<view class="text">{{item.durability}}/100</view>
							</view>
						</view>
						<view class="btn" v-if="active==1" @click="router(`/pages/market/sell?id=${item.id}`)">出售</view>
						<view class="btn cancel" v-if="active==2" @click="cancel(item)">取消出售</view>
					</view>
				</view>
				<u-loadmore :status="loadmore_status" :color="$store.state.loadmoreColor"
					:lineColor="$store.state.loadmoreColor" line @loadmore="loadmore" />
			</view>
		</scroll-view>
		<u-popup :show="popup_show" bgColor="transparent" mode="center" @close="close">
			<CancelSell :item="item" @success="success" @close="close" />
		</u-popup>
	</view>
</template>

<script>
	import {
		orderLists
	} from '@/request/api.js';
	import CancelSell from '@/components/market/CancelSell.vue';
	
	export default {
		components: {
			CancelSell
		},
		data() {
			return {
				active: 1,
				list: [],
				
				item: {},
				popup_show: false
			}
		},
		onShow() {
			this.getList();
		},
		onHide() {
			this.page = 1;
			this.list = [];
		},
		methods: {
			async getList() {
				let data = {};
				if (this.active == 1) {
					data = {
						status: 1,
						product_type: 4,
						page: this.page,
						limit: this.limit
					};
				};
				if (this.active == 2) {
					data = {
						is_sell: 1,
						product_type: 4,
						page: this.page,
						limit: this.limit
					};
				}
				if (this.active == 3) {
					data = {
						status: 10,
						product_type: 4,
						page: this.page,
						limit: this.limit
					};
				}
				let {
					list
				} = await orderLists(data);
				this.last_page = list.last_page;
				list = list.list;
				this.list = this.page == 1 ? list : [...this.list, ...list];
				this.loadmore_status = this.last_page == this.page ? 'nomore' : 'loadmore';
			},
			changeActive(value) {
				this.active = value;
				this.list = [];
				this.page = 1;
				this.getList();
			},
			success() {
				this.popup_show = false;
				this.item = {};
				this.list = [];
				this.page = 1;
				this.getList();
			},
			cancel(item) {
				this.item = item;
				this.popup_show = true;
			},
			close() {
				this.popup_show = false;
				this.item = {};
			}
		}
	}
</script>

<style scoped lang="scss">
	.build {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.tabs {
			height: 100rpx;
			margin-top: 36rpx;
			padding: 0 20rpx;
			box-sizing: border-box;
			background: rgba(31, 11, 5, 0.6);
			display: flex;
			justify-content: space-between;
			align-items: center;

			.item {
				flex: 1;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 36rpx;
				font-weight: 400;
				font-family: LiSu;

				&.active {
					color: #494338;
					background: url(#{$baseImageUrl}/common/active.png) no-repeat;
					background-size: 100% 100%;
				}
			}
		}

		.scroll_view {
			height: calc(100vh - #{$navbarHeight} - 136rpx);
			padding: 30rpx;
			box-sizing: border-box;

			.list {
				.item {
					width: 100%;
					height: 278rpx;
					margin-bottom: 20rpx;
					padding: 44rpx 35rpx 35rpx;
					box-sizing: border-box;
					background: url(#{$baseImageUrl}/common/item_688_278.png) no-repeat;
					background-size: 100% 100%;
					display: flex;

					.cover {
						width: 200rpx;
						height: 200rpx;
						padding: 0 6rpx;
						background: url(#{$baseImageUrl}/bg/372_372.png) no-repeat;
						background-size: 100% 100%;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.item_view {
						flex: 1;
						padding-left: 20rpx;
						box-sizing: border-box;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.grade {
							.key {
								color: #494338;
								font-size: 50rpx;
								font-weight: 400;
								font-family: LiSu;
							}

							.value {
								color: #494338;
								font-size: 42rpx;
								font-weight: 400;
								font-family: LiSu;
							}
						}

						.progress_box {
							width: 100%;
							display: flex;
							align-items: center;

							.key {
								color: #494338;
								font-size: 28rpx;
								font-weight: 400;
								font-family: SimSun;
							}

							.progress_view {
								flex: 1;
								height: 25rpx;
								background: #B4A88E;
								box-shadow: 0px 0px 4px 0px rgba(110, 93, 72, 0.67);
								position: relative;

								.text {
									width: 100%;
									height: 25rpx;
									line-height: 25rpx;
									text-align: center;
									color: #494338;
									font-size: 24rpx;
									font-weight: 400;
									font-family: SimSun;
									box-sizing: border-box;
									position: absolute;
									left: 0;
									top: 0;
									z-index: 2;
								}

								.progress {
									height: 100%;
									background: linear-gradient(90deg, #E68B30, #FAD44C);
								}
							}
						}

						.btn {
							width: 204rpx;
							height: 74rpx;
							line-height: 74rpx;
							text-align: center;
							color: #FFFFFF;
							font-size: 30rpx;
							font-weight: 400;
							font-family: SimSun;
							background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
							background-size: 100% 100%;
							&.cancel {
								background: url(#{$baseImageUrl}/common/btn2.png) no-repeat;
								background-size: 100% 100%;
							}
						}
					}
				}
			}
		}
	}
</style>